<?php
ob_start();
session_start();

$id=$_POST['id'];
$post= $_POST['post'];
$socialnet=$_POST['socialnet'];

//echo$socialnet; break;



  try{      
      
     include_once('restconnection.php'); 
     if(isset($client)){  
         $ctx = stream_context_create(array('http' => array('timeout' => 5))); 
         //retrive base url 
         $url = $_SESSION['basic_url'];
        
         //echo$url;break;
         if($socialnet == 'all'){
             //add service url
            $service_url_fb="/CrossPostingFB?";  
            
            // echo$service_url;break;
            $post= urlencode($post);
            //print_r($post);
            $output_fb = file_get_contents($url.$service_url_fb."id=".$id."&"."message=".$post,0,$ctx);
           // echo$output_fb;break;
            //parse JSON output
            $data_fb = json_decode($output_fb);
           // print_r($data_fb);break;
            $webResult_fb = $data_fb->CrossPostingFBResult;
            //print_r($webResult_fb); 
            
            sleep(1);
          /*  
            $service_url_tw="/CrossPostingTW?";
            $final_url = urlencode($url.$service_url_tw."id=".$id."&"."message=".$post);
            $output_tw = @file_get_contents($final_url,0,$ctx);
          //  print_r($url.$service_url."id=".$id."&"."message=".$post); break;
            //parse JSON output
            $data_tw = json_decode($output_tw);
           // print_r($data_tw); break;
            $webResult_tw = $data_tw->CrossPostingTWResult;
            */
            
             if(($webResult_fb==1)||($webResult_fb==TRUE) && ($webResult_tw==1)||($webResult_tw==TRUE)){
                 
                 ?><label class="green" style="font-size:15px;">Message Posted!</label><?php
             }else{
                  ?><label style="color:red;font-size:15px;">Sorry Error to Post your message!</label><?php 
             }
        }else{
        } 
         
     
        if($socialnet == 'facebook'){
             //add service url
            $service_url="/CrossPostingFB?";  
            
            // echo$service_url;break;
            $final_url = urlencode($url.$service_url."id=".$id."&"."message=".$post);
            $output_fb = @file_get_contents($final_url,0,$ctx);
           // echo$output_fb;break;
            //parse JSON output
            $data_fb = json_decode($output_fb);
           // print_r($data_fb);break;
            $webResult_fb = $data_fb->CrossPostingFBResult;
            //print_r($webResult_fb); 
             if(($webResult_fb==1)||($webResult_fb==TRUE)){
                 
                 ?><label class="green" style="font-size:15px;">Message Posted on Facebook!</label><?php
             }else{
                  ?><label style="color:red;font-size:15px;">Sorry Error to Post your message on Facebook!</label><?php 
             }
        }else{
        }
        if($socialnet == 'twitter'){
           
            $service_url="/CrossPostingTW?";
            $final_url = urlencode($url.$service_url."id=".$id."&"."message=".$post);
            $output_tw = @file_get_contents($final_url,0,$ctx);
          //  print_r($url.$service_url."id=".$id."&"."message=".$post); break;
            //parse JSON output
            $data_tw = json_decode($output_tw);
           // print_r($data_tw); break;
            $webResult_tw = $data_tw->CrossPostingTWResult;
           // print_r($webResult_tw); 
             if(($webResult_tw==1)||($webResult_tw==TRUE)){
                 
                 ?><label class="green" style="font-size:15px;">Message Posted on Twitter!</label><?php
             }else{
                  ?><label style="color:red;font-size:15px;">Sorry Error to Post your message on Twitter!</label><?php 
             }
            
        }
        if($socialnet == 'google'){
              
             ?><label style="color:red;font-size:15px;">Not supported yet!</label><?php
        }
         
     
  }else{
    //echo"ciol";//isset  
  }
            
  }catch (Exception $e){
      
     // print($e);
       
      ?>
             
          
          <label style="color:red;font-size:15px;">Sorry there is an error to post your message!</label>
          
      <?php    
       
   }        
        ?>    


        
